package yxy.cherry.battle.module.affix.skill;

import yxy.cherry.battle.Battle;
import yxy.cherry.battle.Fighter;
import yxy.cherry.battle.module.affix.AffixContext.AffixAction;
import yxy.cherry.battle.module.affix.AffixContext.AffixActionClass;
import yxy.cherry.battle.module.affix.AffixFactory.SkillTypeEnum;
import yxy.cherry.battle.module.affix.Skill;
import yxy.cherry.battle.module.affix.SkillType;
import yxy.cherry.battle.module.record.stream.RecordStreamGroup;
import yxy.cherry.battle.module.record.stream.RecordStream_05_复活;
import yxy.cherry.battle.module.record.stream.RecordStream_SKL;
import yxy.cherry.data.bean.skill;

import java.util.Collection;

/** 复活 */
@SkillType(Type = SkillTypeEnum.复活)
public class Affix_05_复活 extends Skill {

	// 参数1: 回复血量比例
	private int get回复血量比例() {
		return getParam(0);
	}

	public Affix_05_复活(Fighter actor, skill skilldata, int probability, int[] params) {
		super(actor, skilldata, probability, params);
	}

	private RecordStreamGroup steamGroup;

	@Override
	public RecordStreamGroup record() {
		steamGroup = getRecord().stream(new RecordStreamGroup());
		steamGroup.add(new RecordStream_SKL(getActor(), getSkillId()));
		return steamGroup;
	}

	@Override
	public boolean _exec(Collection<Fighter> targets) {
		AffixAction affixAction = getAffixContext().get治疗行动();
		affixAction.set行动者(getActor());
		affixAction.setTargets(targets);
		affixAction.add行动类型(AffixActionClass.复活);

		boolean 有效 = false;
		for (Fighter target : targets) {
			有效 |= _exec(getActor(), target);
		}
		return 有效;
	}

	@Override
	public boolean exec(Fighter actor, Fighter target) {
		if (target.is复活过()) {
			return false;
		}

		if (target.is活着()) {
			return false;
		}

		long 治疗量 = target.get生命() * get回复血量比例() / VALUE_比率分母;

		target.handle复活(治疗量);

		getRecord().get统计().getFighter(actor.getFighterPosition()).addCUR(治疗量);

		// 流脚本
		steamGroup.add(new RecordStream_05_复活(target, 治疗量)).record();

		Battle.battleLogger(6,"复活：出手者："+actor.getName()+"目标："+target.getName()+"目标生命："+target.get生命()+"回复比例"+get回复血量比例()+"最终治疗量"+治疗量);
		return true;
	}

}